﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;

namespace Besture.UI.Admin
{
    public partial class UpdatePwd : BasePage
    {
        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            if (!IsPostBack)
            {
                lblUserName.Text = AdminUserService.AdminLoginUser.LoginName;
            }
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }


        #endregion

        #region 保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            AdminUserDac dac = new AdminUserDac();
            string loginName = AdminUserService.AdminLoginUser.LoginName;
            string oldPassword = StringHelper.GetMD5(txtOldPassword.Value.Trim());
            string newPassword = StringHelper.GetMD5(txtNewPassword.Value.Trim());
            int itmp = dac.UpdatePassword(loginName, oldPassword, newPassword);
            switch (itmp)
            {
                case -1:
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('保存失败！');", true);
                    txtOldPassword.Value = "";
                    txtNewPassword.Value = "";
                    txtConfirmNewPassword.Value = "";
                    break;
                case 1:
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改密码成功，请重新登录！');parent.closeDialog();", true);
                    break;
                case 2:
                    ClientScript.RegisterStartupScript(this.GetType(), "", "alert('原密码不正确！');", true);
                    txtOldPassword.Value = "";
                    txtNewPassword.Value = "";
                    txtConfirmNewPassword.Value = "";
                    break;
            }
        }


        #endregion


    }
}